﻿using System;
using System.Collections.Generic;
using System.Text;
using FunctionalCLR;
using FunctionalCLR.Core;

namespace FunctionalCLR.Core.Function.String {
    public class ConcatNode : FuncNode {

        public ConcatNode()
            : base() {
            base.Value = "concat";
        }

        public override FuncNode GetReversedFunction(int index) {
            throw new NotImplementedException();
        }

        public override object Evaluate() {
            StringBuilder buff = new StringBuilder();

            foreach (Node child in Children) {
                if (!child.GetType().Equals(typeof(StringNode))) {
                    throw new Exception("Only strings are allowed.");
                }

                buff.Append(((StringNode)child).Value);
            }

            return buff.ToString();
        }
    }
}
